package com.hdc.mumuwei.micro_account_server.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * @author Mumuwei
 * @Description
 * @create 2021/11/21 11:02
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    /**
     * 拦截配置
     * @param registry 1
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login", "/user/register", "/user/loginWeixin/*");
    }

    /**
     * 跨域请求配置
     * @param registry 1
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","HEAD","POST","DELETE","OPTIONS")
                .allowCredentials(true)
                .maxAge(3600).allowedHeaders("*");
    }
}
